<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    </head>
<body>
<h2>Hello World!</h2>

<h3>photoUpload</h3>
 <form action="goods/" method="post" enctype="multipart/form-data">
    <input type="hidden" name="_method" value="POST"/><br/>
    名字：<input type="text" name="goodsName"/><br/>
    选择图片：<input type="file" name="img"/><br/>
    介绍：<input type="text" name="goodsIntroduction"/><br/>
    库存:<input type="text" name="stock"/><br/>
    <input type="hidden" name="brandId" value="2">
    <input type="hidden" name="username" value="417">
    <input type="hidden" name="status"  value="1">
    <input type="hidden" name="category"  value="生活用品">
    <input type="hidden" name="goodsVolume"  value="1">
    <input type="hidden" name="goodsWeight"  value="1">
    <input type="hidden" name="goodsPrice"  value="10">

    <input type="submit" value="添加"/> <br/>
  </form>

  <form action="goods/bddcf2b428ce4549a2e6c5f47cbfd02c" method="post" enctype="multipart/form-data">
      <input type="hidden" name="_method" value="POST"/><br/>
      名字：<input type="text" name="goodsName"/><br/>
      选择图片：<input type="file" name="img"/><br/>
      介绍：<input type="text" name="goodsIntroduction"/><br/>
      库存:<input type="text" name="stock"/><br/>

      <input type="hidden" name="brandId" value="2">
      <input type="hidden" name="username" value="417">
      <input type="hidden" name="status"  value="1">
      <input type="hidden" name="category"  value="生活用品">
      <input type="hidden" name="goodsVolume"  value="1">
      <input type="hidden" name="goodsWeight"  value="1">
      <input type="hidden" name="goodsPrice"  value="10">
      <input type="hidden" name="imgUrl" value="http://119.23.54.32:80/cbec/DataStore/GoodsPic417/2/bddcf2b428ce4549a2e6c5f47cbfd02c.png">

      <input type="submit" value="更新"/> <br/>
    </form>

 <form action="goods/bddcf2b428ce4549a2e6c5f47cbfd02c" method="post" enctype="application/x-www-form-urlencoded">
      <input type="hidden" name="_method" value="DELETE"/><br/>

      <input type="submit" value="删除"/> <br/>
 </form>


<a href="brand/company/1342">显示某品牌商公司信息</a><br/>

<a href="brand/goods/417">显示某品牌商所有商品信息</a><br/>

<a href="brand/orders/417">显示某品牌商所有订单信息</a><br/>

<a href="goods/username/417">显示某品牌商所有</a><br/>

<form method="post" enctype="multipart/form-data">
    <input type="file" id="img_url" name="img" >
</form>
<button id="savegood">保存</button>

<form method="post" enctype="multipart/form-data">
    <input type="file" id="img_url2" name="img" >
</form>
<button id="changegood">修改</button>

<form method="post" enctype="multipart/form-data">
    <input type="file" id="logo_url" name="logo" >
</form>
<button id="changebrand">修改</button>


<button id="changeOrder">修改状态</button>

<script src="js/jquery-3.4.1.js"></script>
<script src="js/jquery.min.js"></script>
<script>
    $("#changeOrder").click(function() {
                        var params ={
                            "status": 3
                        };
                        $.ajax({
                            type: "PUT",
                            url: "${pageContext.request.contextPath}/brand/order/id/432432",
                            data: JSON.stringify(params),
                            processData: false,
                            contentType: "application/json;charset=UTF-8",
                            dataType:"json",
                            success: function(data) {
                                if (data.status == "0000") {
                                    window.location.href = "brand-productInput-attr.html";
                                } else {
                                    alert("错误");
                                }
                            }
                        });
                    });
    $("#changebrand").click(function() {
                    var logo_url = document.getElementById("logo_url");
                    var file = logo_url.files[0];
                    console.log(file);
                    var formdata = new FormData();
                    formdata.append("logo",file);
                    formdata.append("brand","1111.2");
                    formdata.append("username","417");
                    formdata.append("brief_introduction",null);
                    formdata.append("logoUrl","http://119.23.54.32/cbec/DataStore/BrandLogo/417/47b0767d393945a7aff7ee5ee9636669.jpg");
                    formdata.append("_method","POST");

                    $.ajax({
                        type: "POST",
                        url: "http://localhost:8080/cbec/brand/brand/47b0767d393945a7aff7ee5ee9636669",
                        data: formdata,
                        processData: false,
                        contentType: false,
                        dataType:"json",
                        success: function(data) {
                            if (data.status == "0000") {
                                window.location.href = "brand-productInput-attr.html";
                            } else {
                                alert("错误");
                            }
                        }
                    });
                });
    $("#changegood").click(function() {
                var img_url = document.getElementById("img_url2");
                var file = img_url.files[0];
                console.log(file);
                var formdata = new FormData();
                formdata.append("img",file);
                formdata.append("goodsName","测试修改3");
                formdata.append("goodsVolume","2.0");
                formdata.append("goodsWeight","2.0");
                formdata.append("category","测试修改3");
                formdata.append("goodsPrice","2.0");
                formdata.append("stock",100);
                formdata.append("goodsIntroduction","测试修改3");
                formdata.append("brandId","2");
                formdata.append("username","417");
                formdata.append("imgUrl","http://119.23.54.32/cbec/DataStore/GoodsPic/417/2/0f21096770714dac88fec75e9223f9c2.jpg");
                formdata.append("status",1);
                formdata.append("_method","POST");

                $.ajax({
                    type: "POST",
                    url: "http://localhost:8080/cbec/goods/0f21096770714dac88fec75e9223f9c2",
                    data: formdata,
                    processData: false,
                    contentType: false,
                    dataType:"json",
                    success: function(data) {
                        if (data.status == "0000") {
                            window.location.href = "brand-productInput-attr.html";
                        } else {
                            alert("错误");
                        }
                    }
                });
            });
    $("#savegood").click(function() {

            var img_url = document.getElementById("img_url");
            var file = img_url.files[0];
            console.log(file);
            var formdata = new FormData();

            formdata.append("img",file);
            formdata.append("goodsName","测试1");
            formdata.append("goodsVolume",1.0);
            formdata.append("goodsWeight",1.0);
            formdata.append("category","测试1");
            formdata.append("goodsPrice",1.0);
            formdata.append("stock",100);
            formdata.append("goodsIntroduction","测试1");
            formdata.append("brandId","2");
            formdata.append("username","400");

            $.ajax({
                type: "POST",
                url: "http://localhost:8080/cbec/goods",
                data: formdata,
                processData: false,
                contentType: false,
                success: function(data) {
                    if (data.status == "200") {
                        window.location.href = "brand-productInput-attr.html";
                    } else {
                        alert("错误");
                    }
                }
            });
        });
</script>
</body>
</html>